Ext.define('PJ.view.registrationmanagement.PreChooseUserList', {
    extend: 'AM.default.DefaultList',
	alias: 'widget.wccPreChooseUserList',
    
    initComponent: function(){
        this.columns = [{
        	header: '学员帐号',
        	dataIndex: 't.login_id',
        	width: 110
        },{
        	header: '姓名',
        	dataIndex: 't.user_name',
        	width: 110
        }, {
            header: '性别',
            dataIndex: 'bb.data_name',
            width: 50
        },{
            header: '年龄',
            dataIndex: 't.birthday',
            flex:1,
            minWidth: 50,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '民族',
            dataIndex: 'bt.data_name',
            flex:1,
            minWidth: 80,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '单位及职务',
            dataIndex: 't.duty_remark',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },/* {
            header: '联系电话',
            dataIndex: 't.mobile_Telephone',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },*/ {
            header: '备注',
            dataIndex: 't.remark',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.' + prototype + '.registrationmanagement.PreChooseUserList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },

    // 新增
    onAddClick: function(){
        var me = this;
        var win = me.up('window');
        var records = me.getSelectionModel().getSelection();
        if(records.length > 1){
			Ext.Msg.show({
				title: '提示',
				msg: '只允许操作一条数据！',
				icon: Ext.Msg.WARNING,
				buttons: Ext.Msg.OK
			});
			return;
		}
        if(gj_onlineLearning_constant.loadType == "jsonp"){
        	var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
        		loadType: gj_onlineLearning_constant.loadType,
                url: me.store.addUrl,
        		extraParams: {
        			openState:me.up('window').openState,
        			searchClassID:me.up('window').classId,
        			searchUserIds: records[0].get('userId')
                }
        	});
        	store1.load(function(rec, operation, success){
        		if(success){
                    Ext.Msg.alert('消息', '添加成功！', function(){
                        var store = me.getStore();
                        store.reload();
                        win.down("usChooseUserList").getStore().load();//刷新已选列表
                        win.quotaOfPeople();//预授人数统计
                    });
                }else{
                    Ext.Msg.alert('消息', operation.error);
                }
        	});
        }else if(gj_onlineLearning_constant.loadType == "ajax"){
            Ext.Ajax.request({
                url: me.store.addUrl,
                params: {
        			openState:me.up('window').openState,
        			searchClassID:me.up('window').classId,
        			searchUserIds: records[0].get('userId')
                },
                success: function(response){
                    var data = response.responseText;
                    var json = Ext.decode(data, true);
                    if (json.success) {
                        Ext.Msg.alert('消息', '添加成功！', function(){
                            var store = me.getStore();
                            store.reload();
                            win.down("wccChooseUserList").getStore().load();//刷新已选列表
                        });
                    }
                    else {
                        Ext.Msg.alert('消息', json.msg);
                    }
                }
            });
        }
    },
    listeners: {
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + "Add").setDisabled(selected.length === 0);
    	},
        viewready: function(){
        	var me = this;
            this.addDocked([{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: false,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80,
                    maxLength: 100
                },
                items: [{
                    fieldLabel: '学员帐号',
                    name: "searchLoginID",
                    emptyText: "请输入学员帐号"
                }, {
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名"
                }],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                    		searchClassID: gridPanel.up('window').classId,
		            		queryType: 1
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                onSelectClick: function(button){
                	var form = this;
                	if (form.grid) {
                        
                        if (!form.getForm().isValid()) {
                            return;
                        }
                        
                        var newParams = form.getValues();
                        var newParams_ = {
                        		searchClassID: me.up('window').classId,
                        		queryType: 1
                        };
                        
                        var store = form.grid.getStore();
                        // 重置翻页属性
                        form.grid.resetPage();
                        
                        // 4.0强制更改store参数写法
                        var params = store.proxy.extraParams;
                        Ext.apply(params, newParams);
                        Ext.apply(params,newParams_);
                        store.isLoad = true;
                        store.load();
                    }
                    else {
                        Ext.Msg.show({
                            title: orchid_lang.promptWindowInfo.warningTitle,
                            msg: default_lang.defaultList.selectWarningMsg,
                            icon: Ext.Msg.WARNING,
                            buttons: Ext.Msg.OK
                        });
                    }
                },
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
    				text: '新增',
    				iconCls: 'addIco',
    				itemId: this.oldId + "Add",
    				scope: this,
    				disabled:true,
    				handler: this.onAddClick
    			}, "->", "->", this.countSelectPanel]
            }]);
            // 触发权限过滤事件
            me.fireEvent("permission", this);
            
            var params = me.store.proxy.extraParams;
            var newParams = {
            		searchClassID: me.up('window').classId,
            		queryType: 1
            };
            Ext.apply(params, newParams);
            this.store.isLoad = true;
            this.store.load();
            
        }
    }
});
